#include "stdafx.h"
#include "SplashScreen.h"

using namespace MomogenkyouSystem;
using namespace MomogenkyouContent;

#pragma warning (disable : 4244)

SplashScreen::SplashScreen()
:	m_iPhase(0)
{
	m_ScreenName = "Splash Screen";
	std::vector<std::string>	_TextureNames;
	_TextureNames.push_back("Data/Base/Title_Text.png");
	_TextureNames.push_back("Data/Base/Brand.png");
	_TextureNames.push_back("Data/Screens/Background.png");
	
	m_ContentManager.LoadTextures(_TextureNames);

	m_pTitleText		=	m_ContentManager.GetTexture("Data/Base/Title_Text.png");
	m_pBrandText		=	m_ContentManager.GetTexture("Data/Base/Brand.png");

	m_fTransitionOffTime=	1.0f;
	//IsModal = false;
}

SplashScreen::~SplashScreen()
{
	m_pTitleText = NULL;
	m_pBrandText = NULL;
	m_ContentManager.ClearContents();
}

void	SplashScreen::Initialize()
{
	m_iPhase = 0;
	m_TitleFadeEffect.Start(0.4f, 1, 0.5f);

	//m_LoadingIndicator.Initialize();

	m_Camera.CalculateOrthographic(800, 450, -1.0f, 1000.0f);

	//m_ScreenState = Active;
}

void	SplashScreen::Shutdown()
{
	//m_LoadingIndicator.Shutdown();
}

void	SplashScreen::Update(const float & fInterval)
{
	//m_LoadingIndicator.Update(fInterval);
	switch(m_iPhase)
	{
	case 0:
		//	Show Game Brand Text
		m_TitleFadeEffect.Update(fInterval);
		if(m_TitleFadeEffect.HasEnded())
		{
			m_TitleFadeEffect.Start(0.4f, 1, 0.5f);
			m_iPhase++;
			ScreenManager::AddScreen(Global::LoadingLogo());
		}
		break;
	case 1:
		//	Show Game Title Text
		m_TitleFadeEffect.Update(fInterval);
		if(m_TitleFadeEffect.HasEnded())
			m_iPhase++;
		break;
	
	case 2:
		if(Global::LoadingLogo()->IsExiting())
		{
			//	Got to menu or play some other thing
			this->ExitScreen();
			ScreenManager::AddScreen(Global::MainMenu());
			m_iPhase++;
		}
		break;
	}
}

void	SplashScreen::ProcessInput()
{
	
}

void	SplashScreen::DrawGameScreen(const float & fInterval)
{
	UNREFERENCED_PARAMETER(fInterval);

	//m_LoadingIndicator.Render();
	
	//	2D
	GraphicsSystem::Device->SetTransform(D3DTS_VIEW, &MomogenkyouHelper::MATRIX_IDENTITY);
	GraphicsSystem::Device->SetTransform(D3DTS_PROJECTION, m_Camera.ProjectionMatrix());

	switch(m_iPhase)
	{
	case 0:
		{
			GraphicsSystem::Device->SetTexture(0, m_pBrandText->Handle);
			Quad::RenderQuad(m_pBrandText->WidthHeight(), MomogenkyouHelper::FLOAT4_ZERO, float4(1, 1, 1, m_TitleFadeEffect.Opacity()),	0);
		}
		break;
	case 1:
		{
			GraphicsSystem::Device->SetTexture(0, m_pTitleText->Handle);
			Quad::RenderQuad(m_pTitleText->WidthHeight(), MomogenkyouHelper::FLOAT4_ZERO, float4(1, 1, 1, m_TitleFadeEffect.Opacity()),	0);
		}
		break;
	}
}